﻿using System;
using System.IO;
using System.Web;

namespace TruyenTranhCrawler.Helper
{
    public class FileHelper
    {
        public static void Remove(string virtualPath)
        {
            try
            {
                File.Delete(GetPhysicalPath(virtualPath));
            }
            catch (Exception ex)
            {

            }
        }
        public static void RemoveFolder(string virtualFolder)
        {
            try
            {
                Directory.Delete(GetPhysicalPath(virtualFolder),true);
            }
            catch (Exception ex)
            {

            }
        }
        public static bool IsExisted(string virtualPath)
        {
            return File.Exists(GetPhysicalPath(virtualPath));
        }

        public static string GetPhysicalPath(string virtualPath)
        {
            if (string.IsNullOrEmpty(virtualPath)) return virtualPath;

            if (virtualPath.StartsWith("~"))
                virtualPath = virtualPath.Remove(0, 1);
            if (virtualPath.StartsWith("/"))
                virtualPath = virtualPath.Remove(0, 1);
            
            return Config.PhysicalStaticFile + virtualPath;
        }
    }
}
